package com.ruoyi.web.controller;


import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.*;
import com.ruoyi.common.core.page.CommonQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.IHomeBannerService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author linxz
 * @since 2025-01-02
 */
@RestController
@RequestMapping("/homeBanner")
public class HomeBannerController extends BaseController {
    @Autowired
    IHomeBannerService service;

    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CommonQuery commonQuery) {
        PageHelper.startPage(commonQuery.getPageNum(), commonQuery.getPageSize());
        return getDataTable(service.getList(commonQuery));

    }


    @PostMapping("/add")
    public AjaxResult add(@RequestBody HomeBanner homeBanner) {
        homeBanner.setStatus(0);
        return toAjax(service.addEntity(homeBanner));
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody HomeBanner homeBanner) {
        return toAjax(service.updateEntity(homeBanner));
    }

    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody CommonDelete commonDelete) {
        return toAjax(service.delete(commonDelete));

    }

    @GetMapping("/tree")
    public AjaxResult bannerTree() {
        return AjaxResult.success(service.getBannerTree());

    }

    @PostMapping("/listBySection")
    public AjaxResult listBySection(@RequestBody QueryBanner queryBanner) {
        return AjaxResult.success(service.getListBySection(queryBanner));

    }

    @GetMapping("/sectionList")
    public AjaxResult getBannerSectionList() {
        return AjaxResult.success(service.getBannerSectionList());

    }

    // 只传 sectionName
    @PostMapping("/idList")
    public AjaxResult getBannerIdList(@RequestBody QueryBanner query) {
        return AjaxResult.success(service.getBannerIdList(query));

    }

    // 根据id获取记录
    @PostMapping("/getBannerById")
    public AjaxResult getBannerById(@RequestBody QueryBannerId queryBannerId) {
        return AjaxResult.success(service.getBannerById(queryBannerId.getId()));

    }


}
